package com.thor.palmmall.rest.patrol.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.palmmall.rest.patrol.APatrolQueryParam;
import com.thor.palmmall.spi.device.SPatrolQueryParam;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SPatrolQueryParamConverter implements Converter<APatrolQueryParam, SPatrolQueryParam> {

  public static SPatrolQueryParamConverter getInstance() {
    if (instance == null)
      instance = new SPatrolQueryParamConverter();
    return instance;
  }

  private static SPatrolQueryParamConverter instance;

  private SPatrolQueryParamConverter() {
  }

  @Override
  public SPatrolQueryParam convert(APatrolQueryParam source) {
    if (source == null) {
      return null;
    }

    SPatrolQueryParam target = new SPatrolQueryParam();
    target.setPage(source.getPage());
    target.setPageSize(source.getPageSize());
    target.setStores(new ArrayList<String>());
    if (source.getStores() != null)
      target.getStores().addAll(source.getStores());
    target.setOrder(source.getOrder());
    target.setUserGroups(new ArrayList<KV>());
    if (source.getUserGroups() != null)
      target.getUserGroups().addAll(source.getUserGroups());
    target.setBizState(source.getBizState());
    target.setDate(source.getDate());
    return target;
  }

}
